package socket_server

import "fmt"

type CmdInterface interface {
	Exec() error
}

type CmdClose struct {
	session *Session
	err     error
}

func (c *CmdClose) Exec() error {
	c.session.close(c.err)
	return nil
}

type CmdWrite struct {
	session *Session
	data    []byte
}

func (c *CmdWrite) Exec() error {
	n, err := c.session.Write(c.data)
	if err != nil {
		c.session.close(err)
		return err
	}
	if n != len(c.data) {
		err = fmt.Errorf("数据长度：%d, 实际发送长度：%d", len(c.data), n)
		c.session.close(err)
	}

	return err
}
